package river_city_ransom.tests;

import river_city_ransom.contracts.Dimensions_C;
import river_city_ransom.contracts.Objet_C;
import river_city_ransom.contracts.Position_C;
import river_city_ransom.implementations.Dimensions_I;
import river_city_ransom.implementations.Objet_I;
import river_city_ransom.implementations.Position_I;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.Objet;
import river_city_ransom.services.Position;
import river_city_ransom.types.ObjetNom;
import exceptions.ComposantError;
import junit.framework.TestCase;


public class Objet_T extends TestCase {
	public void test_init_ok_1() {
		try {
			ObjetNom n = ObjetNom.CINQUANTE_CENTIME;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			assertTrue(o.nom() == n);
			assertTrue(o.estPorte() == false);
			assertTrue(o.estJete() == 0);
			Position p = new Position_C(new Position_I(0, 0, 0));
			p.init(0, 0, 0);
			assertTrue(o.position().equals(p));
			Dimensions d = new Dimensions_C(new Dimensions_I(0, 0, 0));
			d.init(5, 5, 1);
			assertTrue(o.dimensions().equals(d));
			assertTrue(o.valeur() == 50);
			assertTrue(o.bonusDeForce() == 0);
			assertTrue(o.estEquipable() == false);
			assertTrue(o.estMarchandable() == true);
		}
		catch(ComposantError e) {
			System.err.println("Objet::test_init_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_init_ok_2() {
		try {
			ObjetNom n = ObjetNom.CHAINE_DE_VELO;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			assertTrue(o.nom() == n);
			assertTrue(o.estPorte() == false);
			assertTrue(o.estJete() == 0);
			Position p = new Position_C(new Position_I(0, 0, 0));
			p.init(0, 0, 0);
			assertTrue(o.position().equals(p));
			Dimensions d = new Dimensions_C(new Dimensions_I(0, 0, 0));
			d.init(15, 5, 5);
			assertTrue(o.dimensions().equals(d));
			assertTrue(o.valeur() == 0);
			assertTrue(o.bonusDeForce() == 10);
			assertTrue(o.estEquipable() == true);
			assertTrue(o.estMarchandable() == false);
		}
		catch(ComposantError e) {
			System.err.println("Objet::test_init_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_init_ko_1() {
		try {
			int l = -10, h = 20, p = 5;
			Dimensions d = new Dimensions_C(new Dimensions_I(0, 0, 0));
			d.init(l, h, p);
			System.err.println("Objet::test_init_ko_1\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_init_ko_2() {
		try {
			ObjetNom n = null;
			Objet o = new Objet_C(new Objet_I(ObjetNom.UN_DOLLAR));
			o.init(n);
			System.err.println("Objet::test_init_ko_2\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_ramasser_ok() {
		try {
			ObjetNom n = ObjetNom.CHAINE_DE_VELO;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			o.etreRamasse();
			assertTrue(o.estPorte() == true);
			assertTrue(o.estJete() == 0);
		}
		catch(ComposantError e) {
			System.err.println("Objet::test_ramasser_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_ramasser_ko() {
		try {
			ObjetNom n = ObjetNom.UN_DOLLAR;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			o.etreRamasse();
			System.err.println("Objet::test_ramasser_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_jeter_ok() {
		try {
			ObjetNom n = ObjetNom.CHAINE_DE_VELO;
			boolean d = true;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			o.etreRamasse();
			o.etreJete(d);
			assertTrue(o.estPorte() == false);
			assertTrue(o.estJete() == 1);
		}
		catch(ComposantError e) {
			System.err.println("Objet::test_jeter_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_jeter_ko() {
		try {
			ObjetNom n = ObjetNom.CHAINE_DE_VELO;
			boolean d = true;
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			o.etreJete(d);
			System.err.println("Objet::test_jeter_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_deplacer_ok() {
		try {
			ObjetNom n = ObjetNom.POUBELLE_METALLIQUE;
			Position p = new Position_C(new Position_I(0, 0, 0));
			p.init(8, 10, 30);
			Objet o = new Objet_C(new Objet_I(n));
			o.init(n);
			o.deplacer(p);
			assertTrue(o.position().equals(p));
		}
		catch(ComposantError e) {
			System.err.println("Objet::test-deplacer_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}
}
